package com.zjw.video.custom.controller;

import com.zjw.video.common.entity.FileEntity;
import com.zjw.video.common.entity.resp.BaseResp;
import com.zjw.video.custom.service.FileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "文件controller")
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileService fileService;

    @Operation(summary = "文件上传")
    @PostMapping("/upload")
    public BaseResp<FileEntity> upload(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) {
        return BaseResp.success(fileService.upload(file, path));
    }

    @Operation(summary = "文件下载")
    @GetMapping("/download")
    public void download(@RequestParam("path") String path, @RequestParam("name") String name, HttpServletRequest request, HttpServletResponse response) {
        fileService.download(path, name, request, response);
    }
}
